package org.dromara.demo.controller;

/**
 * @ClassName EY-TestController
 * @Description org.dromara.controller
 * @Author menyj
 * @Date 2025/4/5
 **/

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.dromara.demo.domain.TestDemoEncrypt;
import org.dromara.demo.domain.bo.TestDemoBo;
import org.dromara.demo.mapper.TestDemoEncryptMapper;
import org.dromara.demo.service.ITestDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/demo")
public class TestController extends BaseController {

    private final ITestDemoService iTestDemoService;

    @Autowired
    private TestDemoEncryptMapper mapper;

    //@Log(title = "测试单表", businessType = BusinessType.UPDATE)
//@RepeatSubmit
    @PutMapping()
    public R<Void> edit(@RequestBody TestDemoBo bo) {
        return toAjax(iTestDemoService.updateByBo(bo));
    }

    /**
     * 测试数据库加解密
     *
     * @param key   测试key
     * @param value 测试value
     */
    @GetMapping()
    public R<Map<String, TestDemoEncrypt>> test(String key, String value) {
//        if (!encryptEnable) {
//            throw new RuntimeException("加密功能未开启!");
//        }
        Map<String, TestDemoEncrypt> map = new HashMap<>(2);
        TestDemoEncrypt demo = new TestDemoEncrypt();
        demo.setTestKey(key);
        demo.setValue(value);
        mapper.insert(demo);
        map.put("加密", demo);
        TestDemoEncrypt testDemo = mapper.selectById(demo.getId());
        map.put("解密", testDemo);
        return R.ok(map);
    }
}
